package br.com.ffm.praticas.facade;

import java.sql.SQLException;
import java.util.List;

import br.com.ffm.praticas.bean.Category;
import br.com.ffm.praticas.dao.CategoryDAO;



public class CategoryFACADE {
	
	private static CategoryFACADE categoryFACADE;
	private static CategoryDAO categoryDAO;
	
	/**
	 * Constructor of the categoryFACADE
	 */
	private CategoryFACADE(){
		categoryDAO = new CategoryDAO();
	}
	
	/**
	 * Method that return a unique instance of categoryFACADE,
	 * if the instance doesn't exist, create and after return it
	 * @return An instance of CategoryFACADE
	 */
	public static CategoryFACADE getInstance(){
		if(categoryFACADE == null){
			categoryFACADE = new CategoryFACADE();
		}
		return categoryFACADE;
	}
	
	/**
	 * Method that returns all the Categories
	 * @return List<Category>
	 * @throws SQLException
	 */
	public List<Category> getCategories() throws SQLException {
		return categoryDAO.getCategories();
	}
	
	/**
	 * Method that search and return a Category
	 * @param id The id of Category to be found
	 * @return If found the Category returns, else return null
	 * @throws SQLException 
	 */
	public Category getCategory(int id) throws SQLException{
		return categoryDAO.getCategory(id);
	}
	
	/**
	 * Method that search and return a Category
	 * @param description The description of Category to be found
	 * @return If found the Category returns, else return null
	 * @throws SQLException 
	 */
	public Category getCategory(String description) throws SQLException{
		return categoryDAO.getCategory(description);
	}
	
	/**
	 * Method that count the number of categories
	 * @return The number of categories
	 * @throws SQLException 
	 */
	public int count() throws SQLException{
		return categoryDAO.getCategories().size();
	}

}
